fix: isolate callId counter per sandbox for parallel test support#2715
Conversation
|
The implementation looks good, but the tests are failing 🙃 |
The global callId counter in proxy-invoke.js caused calledImmediatelyBefore and calledImmediatelyAfter to fail when tests run in parallel with separate sandboxes. Each sandbox now maintains its own callId counter, passed through the spy/stub/fake creation chain via a context object. Fixes sinonjs#2472
984b721 to
2b77b77
Compare
|
Updated the branch. The failing tests were from the sandbox wrappers using the array helper incorrectly when forwarding arguments into the context-aware spy/stub/fake constructors. That dropped the original stub target metadata, which broke accessor stubs and nested sandbox behavior. The wrappers now use the existing commons array helpers consistently, and Verification:
I could not use |
|
|
Fixed in Ran:
|
When tests run in parallel with separate sandboxes, the \calledImmediatelyBefore\ and \calledImmediatelyAfter\ assertions fail unexpectedly. This happens because proxy-invoke.js uses a global \callId\ counter shared across all sandboxes.
The fix introduces a per-sandbox context object that holds its own \callId\ counter. Each sandbox passes this context through the spy/stub/fake creation chain, and the proxy stores it for use during invocation.
Implementation:
Added tests that verify call order assertions work correctly across independent sandboxes.
The public API remains unchanged. Direct use of \sinon.spy()\ without a sandbox uses a shared default context (same behavior as before), while sandbox-created spies/stubs/fakes get isolated counters.
Fixes #2472